﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ninject;
using System.Web.Mvc;
using Moq;
using MMITDomain.Abstract;
using MMITDomain.Concrete;
using MMITWeb.Infrastructure.Abstract;
using MMITWeb.Infrastructure.Concrete;
using Ninject.Syntax;
using MMITCore.Abstract;
using MMITCore.Logging;


namespace MMITWeb.Infrastructure
{
    public class NinjectDependencyResolver : IDependencyResolver
    {
        private IKernel ninjectKernel;

        public NinjectDependencyResolver()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }

        #region IDependencyResolver Members

        public object GetService(Type serviceType)
        {
            return ninjectKernel.TryGet(serviceType);
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return ninjectKernel.GetAll(serviceType);
        }

        #endregion

        public IBindingToSyntax<T> Bind<T>()
        {
            return ninjectKernel.Bind<T>();
        }

        public IKernel Kernel
        {
            get
            {
                return ninjectKernel;
            }
        }
        private void AddBindings()
        {
            ninjectKernel.Bind<IVoucherRepository>().To<EFVoucherRepository>();
            ninjectKernel.Bind<IAuthProvider>().To<FormsAuthProvider>();
            ninjectKernel.Bind<IAccountRepository>().To<EFAccountRepository>();
            ninjectKernel.Bind<ICustomerRepository>().To<EFCustomerRepository>();
            ninjectKernel.Bind<IRuleRepository>().To<EFRuleRepository>();
            ninjectKernel.Bind<ITransactionChargeRepository>().To<EFTransactionChargeRepository>();
            ninjectKernel.Bind<ICountryRepository>().To<EFCountryRepository>();
            ninjectKernel.Bind<IIdentificationTypeRepository>().To<EFIdentificationTypeRepository>();
            ninjectKernel.Bind<ITransactionRepository>().To<EFTransactionRepository>();
            ninjectKernel.Bind<ITransactionRoleRepository>().To<EFTransactionRoleRepository>();
            ninjectKernel.Bind<ITransactionRoleAccountRepository>().To<EFTransactionRoleAccountRepository>();
            ninjectKernel.Bind<ITransactionTypeRepository>().To<EFTransactionTypeRepository>();
            ninjectKernel.Bind<ICurrencyRepository>().To<EFCurrencyRepository>();
            ninjectKernel.Bind<IChargeRepository>().To<EFChargeRepository>();
            ninjectKernel.Bind<INotificationManager>().To<NotificationManager>();
            ninjectKernel.Bind<ILogger<SynkronLogger>>().To<SynkronLogger>().WithConstructorArgument("category", "MMITWeb");
            ninjectKernel.Bind<ITemplatePath>().To<ResourceTemplatePath>();
            ninjectKernel.Bind<IPartnerRepository>().To<EFPartnerRepository>();
        }


    }
}